package design_pattern.singleton;


/**
 * @Description : 懒加载，线程安全，静态内部类
 * Created by cyd on 2021-02-02 13:38:41
 */
public class SingleTonByEnum {
    public static void main(String[] args) {
        // 测试，拿到的实例是同一个对象
        Singlton08 instance = Singlton08.INSTANCE;
        Singlton08 instance1 = Singlton08.INSTANCE;
        System.out.println(instance == instance1);
        instance.sayHello();
        Singlton08.sayBye();
    }
}

/**
 * @author: cyd
 * @Description: TODO
 * @DateTime: 2021/2/7 14:58
 */
enum Singlton08 {
    INSTANCE {
        private String name;
        private Integer age;
    };
    

    public void sayHello() {
        System.out.println("hello");
    }


    public static void sayBye() {
        System.out.println("bye");
    }
}
